package com.youlv.yl.service.impl;

import com.youlv.yl.dto.HotelOne;
import com.youlv.yl.dto.HotelQueryDto;
import com.youlv.yl.entity.hotel.Hotel;
import com.youlv.yl.dao.HotelDao;
import com.youlv.yl.service.intf.HotelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlv.yl.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 酒店详情 服务实现类
 * </p>
 *
 * @author fenghe
 * @since 2022-01-05
 */
@Service
public class HotelServiceImpl extends ServiceImpl<HotelDao, Hotel> implements HotelService {
    @Autowired
    private HotelDao dao;

    @Override
    public R selectHotel(HotelQueryDto hotel) {
        if(hotel.getCity() != null && !hotel.getCity().isEmpty()) {
            String[] split = hotel.getCity().split("/");
            for (int i = 0; i < split.length; i++) {
                hotel.setProvince(split[0]);
                hotel.setCity(split[1]);
                hotel.setArea(split[2]);
            }
        } else {
            hotel.setCity(null);
        }
        if(hotel.getHotelName().isEmpty()) {
            hotel.setHotelName(null);
        }
        if(hotel.getHotelRank().isEmpty()) {
            hotel.setHotelRank(null);
        }
        List<HotelQueryDto> hotels = dao.select(hotel);
        if(hotels.size() > 0) {
            return R.ok(hotels);
        }
        return R.fail("无查询结果，请稍后重新输入");
    }

    @Override
    public R selectAll(Integer tid) {
        List<HotelQueryDto> hotelQueryDtos = dao.selectAll(tid);
        if(hotelQueryDtos.size() > 0) {
            return R.ok(hotelQueryDtos);
        }
        return R.fail("无查询结果，请稍后重新输入");
    }

    @Override
    public R selectOne(HotelOne hotelOne) {
        List<HotelOne> hotel = dao.selectOne(hotelOne);
        if(hotel != null) {
            return R.ok(hotel);
        }
        return R.fail("无查询结果，请稍后重新输入");
    }
}
